<?php
namespace Weixin\Controller;

class SucaiController extends BaseController{
    public function index(){
        if(IS_POST){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Uploads/'; // 设置附件上传根目录
        if(!file_exists($upload->rootpath)){
            mkdir($upload->rootpath,0777,true);
        }
        $upload->savePath=''; // 设置附件上传（子）目录// 上传文件
        $info = $upload->upload();
        $image_path = realpath($upload->rootPath.$info["images"]["savepath"].$info["images"]["savename"]);//把相对路径转化成绝对路径
        if(version_compare(PHP_VERSION,"7.0.0",">=")){
            $image_path =new \CURLFile($image_path);
        }else{
            $image_path="@$image_path";
        }

        $access_token=$this->access_token;
        $url ="https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$access_token&type=image";

        $fields = array(
            "media"=> $image_path
        );
        $res = $this->curl($url,$fields);
            print_r($info);die;
        }
        $this->display();
    }

    public function sucai(){
        $access_token=$this->access_token;
        $url ="https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=$access_token";
        $fields=<<<php
{
"media_id":"296855dd74711f1816b6806b8caa98f7ebf278f0";
}
php;
        $res = $this->curl($url,$fields);

    }
}